Part Number Hot Search : 
THN5601B 05111 80C51 BZX84C47 BSV52L CM2324 2SK1486 TL062CN
Product Description
Full Text Search
 

To Download AN2618 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  september 2013 rev 2 1/23 AN2618 application note etpu host interface introduction the etpu is the new generation of time processing unit (tpu). besides the hardware enhancement, significant improvements have been made to the accompanying software development tools; these tools make the enhan ced time processing unit (etpu) easy to use. a high level language (c) compiler has been developed to allow the user to program the etpu by using c language instead of microcode. to program the etpu effectively, the programm er still needs to have a clear understanding of how the etpu hardware works. coding in c, the programmer can focus more on the application logic and leave the mechanics of the etpu programming to the compiler (i.e., register usage and tracking, parameter packing, micro-instruction packing, etc.). with the help of the etpu simulator and debugger, etpu software can be developed much like the software for the host cpu. productivity of software development can be significantly improved. the introduction of the etpu c compiler also changes the way the host interfaces to the etpu functions. with the help of the compiler, the same symbol can be referenced by the both etpu and host software. the host software can interface with etpu functions via api functions, instead of accessing physical memory locations and registers. for each etpu function, a host interface api function can now be developed as a part of the etpu c program. the host application can call these api functions to interface with the etpu. the references to these api functions and symbols for parameters are resolved at compile time. the implementation details of the etpu functions are hidden from the host application. this design improves the flexibility of the etpu functions? implemen tation and the portability of the host application code. this application note discusses how to build the host interface for etpu functions. this application note shows how to build the ho st interface to access etpu functions. the etpu pwm driver is used as an example to illustrate what the host needs to do to configure etpu module, channel and initialize pwm function. the apprev 2lication note also describes the details of how to export etpu software information to the host compiler. the working code example is presented in the appendix. the user can compile both host and etpu code, then download to actual hardware for testing. www.st.com
contents AN2618 2/23 contents 1 overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 2 etpu and host interface hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 3 host interface software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 3.1 initialization overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 3.2 etpu module initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 3.3 etpu channel initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 3.4 etpu function initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 3.5 etpu and host interactive control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 4 software integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 5 conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 appendix a code example 1.ma in.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 appendix b code example 2.etpu_p wmcontrol.h . . . . . . . . . . . . . . . . . . . . . . . 12 appendix c code example 3.etpuc_pwm .c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 appendix d code example 4.etpuc_ima ge.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 appendix e code example 5.etpu_pwm_auto.h . . . . . . . . . . . . . . . . . . . . . . . . . 17 appendix f code example 6.utility.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 appendix g code example 7.etpu_pwm.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 6 revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
AN2618 overview 3/23 1 overview host interface software adds another layer of abstraction between the host cpu and etpu. the host interface api functions hide the complexity of the interaction between the host cpu and etpu, providing a simple interface for host applications. ideally, every etpu function shall have one or more host interface api functions. the interface software between host an d etpu facilitates three major tasks: 1. etpu hardware initialization ? configure etpu peripheral hardware 2. etpu function initialization ? pass initial parameters and initiate function execution 3. etpu function run time interactive control ? update function parameters and handle handshaking once the etpu peripheral and etpu functions are initialized, each etpu function can start to execute with initial function parameters. the host interface api functions need to be provided for interactive control (i.e. parameters updating and control mode changing etc.). to update the parameter or change control mode, the host is responsible for passing updated parameters to the etpu functions, and then informing the etpu that the function parameters have changed. if a coherent change of function parameters is required, the logic has to be built in the etpu functions to ensur e the coherency. for some etpu functions, the interaction between host and etpu is an essential part of the operation. in both host and etpu software, the logic is needed to handle the handshaking between host and etpu. the interaction between the etpu and host can be encapsulated in the host interface api functions. the host code and etpu code are compiled by different compilers. the host compiler is normally used to build a single code image for both host and etpu. in order to build etpu code and host code together, the etpu software building information (i.e. etpu code image) has to be exported to the host compiler. the symbol information has to be exported from the etpu compiler to the host compiler as well. for the byte craft etpu compiler, the mechanism is implemented as a set of host interface macros. in the etpu code, these macros are inserted to generate proper executable and symbol information for the host compiler. the host interface design process is illustrated in the etpu pwm driver examples in the appendices.
etpu and host interface hardware AN2618 4/23 2 etpu and host interface hardware the host interface hardware for the etpu is shown in figure 1 . the host and etpu can communicate to each other via event or by data. the host has access to all etpu host interface registers. when the host wants the etpu?s services, it can issue the host service request (hsr) by writing the etpu channel control registers. once the host service request is acknowledged, a thread of etpu code associated with this hsr is activated for execution. the etpu code in the thread implements the functions requested by the host. when etpu needs the host service, it can issue the interrupt request or dma data transfer request, or generate a global exception. the events handling logic is needed in the host software to provide services to the etpu corresponding to these requests. the etpu code memory (ram) and data memory (ram) are accessible by both host and etpu. etpu code memory stores the etpu executable binary image. at the power up initialization, following the defined sequences, the host transfers the etpu code stored in the flash memory to the etpu code memory. during the execution, the etpu micro-engine fetches the micro-instructions from the code memory. figure 1. etpu host interface hardware the etpu data memory is implemented by using tri-port ram. it provides for data sharing between the host and etpu engines. both host and etpu can read and write the etpu data memory in any data size (8, 16, 24, and 32 bit). since the etpu data bus is 24 bits wide, it is best to pack together a data word with an 8 bit value and a 24 bit value in order to reduce data memory utilization. to reduce the overhead of pa cking and unpack ing the data, a virtual mirror memory space of the normal etpu data memory has been created. the virtual memory space is called parameter si gn extension (pse) memo ry space. when the host reads the 32-bit data from the pse memory space, it will return the sign extended 24- bit data. the conversion is needed if the 24-bit data is unsigned. similarly, when the host writes the 32-bit data to the etpu pse memory, only the three least significant bytes will be written to the etpu data memory. the most significant byte is untouched.
AN2618 host interface software 5/23 3 host interface software the function partition between the application software and low-level driver is defined during the software architecture design. to make the software portable, the application software is normally designed to interface with the low-level driver via abstracted interface apis. the host interface of the etpu functions should be designed such that the implementation of the low-level driver is hidden from the application software. once the application software interface to the low-level driver is defined, the functionality of the low-level driver can be partitioned between host cpu and etpu. the etpu interface software running on the host cpu is an integral part of the low-level driver. it handles the details of the interaction between host and etpu. the etpu code and host interface code are compiled by two different compilers. in order to resolve the etpu code symbol reference in the host code, it is necessary to export the symbolic information from the etpu compiler to th e host compiler. similarly, to build a single executable image, it is necessary to export etpu code image to the host compiler. several types of information are exported from etpu_c through host interface files, generated from #pragma write statements during compilation. for detailed information on #pragma write , see the etpu_c documentation. an example of application software and low-level driver partition is shown in appendix a on page 11 . 3.1 initialization overview the etpu initialization is an important part of the host interface. at the power up, the host has to configure the etpu peripheral properly before the etpu function can be executed. the etpu initialization process is accomplis hed by both host cpu and etpu. during the initialization, the functional partition between host cpu and etpu is as follows: host responsibility : etpu module initialization etpu channel configuration providing initial etpu function parameters initiating the etpu function execution etpu responsibility : responding to the hsr transitioning into t he initialization state the etpu initialization can be broken down in to three steps: etpu m odule initialization, etpu channel initialization and etpu function initialization. the following sections discuss the interface design and the data exchange between host cpu and etpu for each step of initialization. 3.2 etpu module initialization at the power up initialization, the etpu peripheral hardware is configured by the host. the etpu module initialization includes the following steps:
host interface software AN2618 6/23 1. initialize etpu global registers ? etpu misc compare regi ster (etpu_misccmpr) ? etpu module configuration register (etpu_mcr) ? etpu time base configuration register (etpu_tbcr) ? etpu stac bus configuration register (etpu_stacr) ? etpu engine configuratio n register (etpu_ecr) 2. load etpu code from flash memory to etpu code ram 3. copy initial values of etpu code global variables to etpu data memory most of the information required to configure the etpu global registers are not dependent on the etpu software implementation (i.e., time base, clock frequency, entry table address, etc.). the configuration information is determined during the host peripheral configuration and resource allocation. only the misc value depends on the actual etpu software implementation; it has to be exported to the host program after the etpu code is compiled. the etpu_c compiler provides a macro ( ::etpumisc ) to calculate the misc value of the etpu code image (see appendix c on page 13 ). the etpu code image is generated when the etpu c program is compiled. to use this code in the host program, the etpu code image can be exported as an array of constant values. the etpu_c compiler provides a macro ( ::etpucode ) to generate and export the etpu code image (see appendix c on page 13 ). the etpu code image constant array is suitable to be included in the host source code. the host compiler locates the etpu code image array in the flash memory at host source code compile time. since the etpu micro- engine can only fetch micro-instructions out of etpu code memory (ram), at the power up initialization, the etpu code image has to be loaded to etpu code memory. as it is in the standard c syntax, when the etpu code is compiled, the global variables are allocated to the etpu data memory and the initial values are assigned to the corresponding memory locations. the standard c syntax requires that all global variables are declared outside of any function. for etpu, this means that all global variables have to be declared outside of any execution thread. since only the code in a thread can be executed on etpu, the global variable initial value assignment statements will not be executed. the global variables cannot be initialized in the etpu code; they must be initialized by the host. the software statements have to be added to the host code to initialize the etpu global variables. the initialization va lues have to be exported from the etpu compiler to host compiler. the etpu_c compiler provides a macro ( ::etpuglobalimage ) to capture initial values for all global variables and exports them as a constant array ( appendix d on page 16 ). at power up initializ ation, the global variable initial values are loaded to the etpu data memory for global variables. the host interface macros have to be added to the etpu code in #pragma write statements to export the etpu software information to the host compiler ( appendix c on page 13 ). these statements will genera te header files that contain the misc value, etpu code image and global variable memory image ( appendix d on page 16 ). the software for the etpu module initialization can be encapsulated in an api function. an example of the etpu module initialization function implementation is provided in appendix f on page 18 ( mc_etpu_init() ).
AN2618 host interface software 7/23 3.3 etpu channel initialization after the etpu module is configured, each channel on the etpu module can be configured. etpu channel initialization includes the following tasks: 1. etpu channel configuration registers initialization ? assign etpu function to a channel ? setup channel priority ? configure interrupt/dma/output enable ? select etpu function entry table encoding ? assign the function frame to a channel 2. etpu channel status control register initialization ? set up etpu function mode the etpu channel assignment and the channel priority determination are a part of the host software architecture design. they are independent of the etpu functions implementation. the information for the configuration is provided by the host software design. during the channel initialization, a section of etpu data memory is assigned to each channel. this memory section is called the ?function frame?. the function frame contains all the function parameters and static local variables used by the etpu function. the starting address of the function frame is assigned to the channel at initialization. the function frame assignment can be static or dynamic. dynamic allocation assigns the function frame to the channel based on the next av ailable memory space. the av ailability of th e etpu data memory depends on the number of functions that have been assigned and the number of parameters the function is using. dynamic allocation can reduce the etpu data memory consumption by minimizing unused memory ?holes?. to allocate the function frame dynamically, the host must know the function frame consumption by a particular etpu function. the etpu_c compiler provides a macro ( ::etpuram ) to report the number of parameters and static local variables used by a function at compile time ( appendix c on page 13 ). the etpu function table entry encoding, interrupt enable, dma enable, output enable, output polarity, and function mode are constants specific to the etpu function software implementation. it is a good practice to define them only once in the etpu code and export the configuration information at compile time. once the host interface macros are added to the etpu code ( appendix c on page 13 ), the #pragma write statements will generate a header file that contains all the etpu function configuration and software symbol information at compile time ( appendix e on page 17 ). the header file can be included in the host interface code to resolve symbol references. 3.4 etpu function initialization the etpu function initialization is the last step of the etpu initialization process. during the etpu function initialization, the host is responsible for passing the parameters to the etpu functions and initiating the etpu function execution by issuing a host service request. once the host service request for initialization is recognized, the etpu will transition to the initialization state. unlike in the host cpu, the etpu function parameters passed from host are not placed on the stack. instead, memory in the function frame is allocated to accommodate every function parameter. the host passes the etpu function parameters by writing directly to the etpu
host interface software AN2618 8/23 function frame. the host needs to know the function frame for each channel, as well as the data type and address offset for every parameter. the function frame can be obtained by reading the etpu channel base address register. the etpu_c compiler provides the host interface macros to export the offset of each function parameter; use them in #pragma write directives to export this information. the function parameters can be 8-bit, 16-bit, or 32-bit. the etpu compiler can allocate function parameters at 8-, 16-, 24-, or 32-bit boundaries. to pass 8-bit or 16-bit parameters, the host can directly write to etpu data memory. most etpu data registers and timers are 24-bit. to pass 24-bit etpu function parameters, the host needs to pass a 32-bit parameter to the etpu. since the host cannot access etpu data memory on the 24-bit boundary, the host code needs to realign the parameter to the 32-bit address boundary before wr iting it to the function frame. it is the responsibility of the host to ensure the function para meters are within proper range. it is also the responsibility of the host when writing the 24-bit parameter to ensure that the upper byte on the function frame is not corrupted. similarly, when reading a 24 bit return value from the function frame, the host code must mask the upper byte before returning the correct 24 bit value. to simplify the interface code, it is recommended to acce ss the 24-bit function parameter by using pse memory space. an example of the etpu function initialization is listed in appendix g on page 20 ( etpu_pwm_init() ). 3.5 etpu and host interactive control once the etpu function is initialized, it will st art execution based on the initial parameters and input/output conditions. the etpu function can provide the api for the host application code to update the function parameter or change the control mode. similarly, the host software has to provide proper logic to handle the etpu interrupt or dma requests. the software to handle the host and etpu interaction has to cross between two different compilers. when the host initiates the etpu function, the data flows from the host to etpu. this behavior is the same as the ?call by value? protocol in the standard c syntax. sometimes ?call by reference? is desired to ac cess etpu function internal variables. since the data flow for ?call by reference? has to cross both compilers, it is not directly supported by the compilers. however, the behavior of the ?call by reference? can be implemented in the host interface software. the host interface software can pass a reference to the api function to access the etpu function internal variables. an example of the ?call by reference? implementation is shown in both appendix a on page 11 and appendix g on page 20 ( etpu_pwm_getstarttime() ) some etpu functions require host or dma service. the etpu software can write the circ bits in the channel interrupt and data transfer request register to send the request to the host or dma. the interrupt service routine must be added and the dma channel must be configured in the host code to respond to the etpu request. the host interface software has to provide functions to update etpu function parameters or change the control mode during the normal operation. similar to the function initialization api, the interface api function needs to check the validity of the parameters, write them to the etpu data memory, and then issue the host service request to inform etpu that the parameters are newly updated. an example of the update pwm function parameter is shown in appendix g on page 20 ( etpu_pwm_update() ) .
AN2618 software integration 9/23 4 software integration the etpu code and host cpu code are compiled and linked separately. the etpu code needs to be built first to generate and export the etpu code image and parameter symbol information, as shown in appendix d on page 16 and appendix e on page 17 . the host code needs to include these files properly to resolve all the symbol reference between etpu and host code. this software build dependency can be added easily to the makefile to ensure the proper sequence.
conclusion AN2618 10/23 5 conclusion the benefit of the host interface design is to isolate any hardware dependency from the application software by means of the host interf ace api functions. in the etpu host interface design, all the interactions between host and etpu are encapsulated in the interface api functions. with this interface design, the implementation of the low-level driver can be hidden from the host application. in the pwm example, the application software interfaces to a generic pwm driver with two control parameters: period and duty cycle. when the etpu implementation of the pwm is changed, the host application software does not need to change. for the host application software, it does not make any difference if the low-level pwm driver is implemented by using a general purpose discrete output, emios timer channel, or etpu channel.
AN2618 code example 1.main.c 11/23 appendix a code example 1.main.c #include "etpu_image.h" #include "etpu_pwmcontrol.h" /*********************************************************************************************** * function: main * * purpose: this function is the entry point of the host pwm application. the main function * * initializes the etpu to execute pwm function. once the etpu pwm function is initialized, * * the main function calls the api function periodically to update the * pwm function parameters.* ***********************************************************************************************/ void main(void) { unsigned long dutycycle_host = 0x200000; uint16_t delay_counter; uint32_t pulsestarttime; /* init device */ init_error = etpu_init(); /* main user code goes here */ while(1) { for (delay_counter=0; delay_counter <= 0x0fee; delay_counter++) {} if (dutycycle_host == 0x800000) dutycycle_host = 0x400000; else dutycycle_host = 0x800000; etpu_pwm_update(pwm0, 4000, dutycycle_host); etpu_pwm_getpulsetime(pwm0, &pulsestarttime); } /********************************************************************************************** * function: etpu_init * * purpose: this function initializes etpu module & configures each etpu channel. the channel * * the etpu pwm functions initialization apis are called to initiate etpu function execution. * **********************************************************************************************/ int16_t etpu_init () { int16_t error_code; uint32_t chanconfigparam = 0; /* initialize etpu hardware */ mc_etpu_init(etpu_config_a, (uint32_t *)etpu_code,(uint8_t)etpu_code_ram_size, (uint32_t *)etpu_globals); /* initialize etpu channels */ chanconfigparam = (etpu_pwm_int_req | etpu_pwm_dma_req | etpu_pwm_out_disable | \ (etpu_pwm_table_select << 24) | (pwm0_chan_priority << 28)); mc_etpu_chan_init(pwm0, etpu_pwm_function_number, etpu_pwm_func_mode, \ etpu_pwm_num_parms, chanconfigparam, auto_func_frame); /* initialize etpu functions */ etpu_pwm_init(pwm0, 4000, dutycycle_host); /* enable all timebases */ mc_mpc5500_timer_start(); return (0); }
code example 2.etpu_pwmcontrol.h AN2618 12/23 appendix b code example 2.etpu_pwmcontrol.h /*--------------------------------------------------------------------+ | include header files | +--------------------------------------------------------------------*/ #include "mpc5554.h" //mpc5554 register definitions. #include "mpc5500_util.h" //useful utility routines. #include "etpu_image.h" /*--------------------------------------------------------------------+ | constants definition | +--------------------------------------------------------------------*/ /* define functions to channels */ #define pwm0 0 #define pwm0_chan_priority3 #define etpu_entry_table 0x0 // etpu entry table address struct etpu_config_t etpu_config_a = { etpu_misc_enable, //mcr register etpu_misc_val,//misc value from etpu compiler link file //configure etpu engine a etpu_filter_clock_div8 + etpu_chan_filter_3sample + etpu_entry_table, //configure etpu engine a timebases etpu_tcr2ctl_div8 + ( 7 << 16) + //tcr2 prescaler of 8 (7+1) etpu_tcr1ctl_div2 + 3, //tcr1 prescaler of 4 (3+1) 0, //configure etpu engine b etpu_filter_clock_div4 + etpu_chan_filter_3sample + etpu_entry_table, //configure etpu engine b timebases etpu_tcr2ctl_div8 + ( 7 << 16) + //tcr2 prescaler of 8 (7+1) etpu_tcr1ctl_div2 + 3, 0 };
AN2618 code example 3.etpuc_pwm.c 13/23 appendix c code example 3.etpuc_pwm.c #include /*--------------------------------------------------------------------+ | global variable definitions | +--------------------------------------------------------------------*/ int dutycycle = 500; /******************************************************************************** * function: pwm * * purpose: this is the etpu function that modulate an etpu output pin as pwm * * signal based on the host service request and the parameters passed * * from the host. * * * * inputs notes: this function has 2 parameters * * returns notes: n/a * * * * warning: * ********************************************************************************/ void pwm(int period, unsigned fract24 duty) { static int starttimehi; int hightime; if (hsr == hsrinitpwm) // init pwm hsr -- required to initialize the signal. { initpwm: setchannelmode(em_nb_dt); setupmatch_b(tcr1, mtcr1_ctcr1_ge, low_high);//set output high immediately } else if (matcha_transb)// here on match1 (falling edge) { fallingmatch: clearmatchalatch(); setupmatch_b((starttimehi + period), mtcr1_ctcr1_ge, low_high); //set up for rising match } else if (matchb_transa) // here on match2 (rising edge) { risingmatch: clearmatchblatch(); starttimehi = getcapregb(); // store the time the pulse transition to high if (duty == 0xffffff) // special case for 100% modulation { hightime = 32 ; // arbitrary value having no efect on the output signal setupmatch_a(hightime, mtcr1_ctcr1_ge, match_no_change); } else { hightime = period * duty + starttimehi; setupmatch_a(hightime, mtcr1_ctcr1_ge, high_low); //setup for falling match } } else
code example 3.etpuc_pwm.c AN2618 14/23 { //this else statement is used to catch all unspecified entery table conditions } } #pragma endlibrary; /* information exported to host cpu program */ #pragma write h, (::etpufilename (etpu_pwm_auto.h)); #pragma write h, (/* warning this file is automatically generated do not edit it! */); #pragma write h, ( ); #pragma write h, (::etpuliteral(#ifndef __etpu_pwm_auto_h)); #pragma write h, (::etpuliteral(#define __etpu_pwm_auto_h)); #pragma write h, ( ); #pragma write h, (/* function configuration information */); #pragma write h, (::etpuliteral(#define etpu_pwm_function_number) pwm_function_number ); #pragma write h, (::etpuliteral(#define etpu_pwm_table_select) ::etpuentrytype(pwm) ); #pragma write h, (::etpuliteral(#define etpu_pwm_num_parms) ::etpuram(pwm) ); #pragma write h, ( ); #pragma write h, (::etpuliteral(#define etpu_pwm_int_enable) pwm_int_enable ); #pragma write h, (::etpuliteral(#define etpu_pwm_dma_enable) pwm_dma_enable ); #pragma write h, ( ); #pragma write h, (::etpuliteral(#define etpu_pwm_out_dis) pwm_out_disable ); #pragma write h, (::etpuliteral(#define etpu_pwm_func_mode) pwm_function_mode ); #pragma write h, ( ); #pragma write h, (/* host service request definitions */); #pragma write h, (::etpuliteral(#define etpu_pwm_init) hsrinitpwm ); #pragma write h, (::etpuliteral(#define etpu_pwm_update) hsrupdtpwm ); #pragma write h, ( ); #pragma write h, (/* parameter definitions */); #pragma write h, (::etpuliteral(#define etpu_pwm_period_offset) ((::etpulocation(pwm,period)?1)/4)); #pragma write h, (::etpuliteral(#define etpu_pwm_duty_offset) (::etpulocation(pwm, duty)-1)/4 ); #pragma write h, ( ); #pragma write h, (::etpuliteral(#endif /*__etpu_pwm_auto_h */ )); /* information exported to host cpu program */ #pragma write m, (::etpufilename (etpu_image.h)); #pragma write m, (/* warning this file is automatically generated do not edit it! */); #pragma write m, ( ); #pragma write m, (::etpuliteral(#ifndef __etpu_image_h)); #pragma write m, (::etpuliteral(#define __etpu_image_h)); #pragma write m, ( ); #pragma write m, (/* etpu code ram constants definitions */); #pragma write m, (::etpuliteral(#define etpu_code_ram_size) etpu_code_image_size); #pragma write m, (::etpuliteral(#define etpu_misc_val) ::etpumisc); #pragma write m, ( ); /* global const initialization array */ #pragma write m,( const uint32_t etpu_globals[]= { ::etpuglobalimage32 };);
AN2618 code example 3.etpuc_pwm.c 15/23 #pragma write m, ( ); /* this is an example of a code as a constant array */ #pragma write m,( const uint32_t etpu_code[]= { ::etpucode32 };); #pragma write m, ( ); #pragma write m, (/* end of etpu code image */); #pragma write m, (::etpuliteral(#endif /*__etpu_image_h */ ));
code example 4.etpuc_image.h AN2618 16/23 appendix d code example 4.etpuc_image.h /* warning this file is automatically generated do not edit it! */ #ifndef __etpu_image_h #define __etpu_image_h /* etpu code ram constants definitions */ #define etpu_code_ram_size 2 #define etpu_misc 0x0ef38a79 const uint32_t etpu_globals[]= { 0x000001f4,0x00000000 }; const uint32_t etpu_code[]= { 0x4fffffe7,0x3bfc3ff4,0x4f3f0f9f,0xf73ffcfb, 0xdfef7a80,0xbfe80a82,0x3b193ff4,0x4f3f0f9f, 0xf73ffcfb,0x7ff37fbb,0xbffffb82,0xbfeffb81, 0x1fffffec,0x3838fff4,0xf0c0029f,0x1c8f5f96, 0x3bf42ff4,0x48f0fe7f,0xff3ffcfb,0xf7c003df, 0xbfeffb80,0xbfe80a81,0x3b190fe9,0xf34802ff, 0x3bf70fb4,0xbfeffb82,0x3b195fd4,0x3bf42ff4, 0x4af0fe7f,0xff3ffcfb,0x6fffffff,0x6fffffff, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x40004000,0x40004000,0xc01fc01f,0xc01fc01f, 0xc01fc01f,0x40044004,0x40094009,0x40094009, 0x40044004,0x40044004,0x40044004,0x40044004, 0xc01fc01f,0xc01fc01f,0x40094009,0x40044004, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, .... 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000 }; #endif /*__etpu_image_h */
AN2618 code example 5.etpu_pwm_auto.h 17/23 appendix e code example 5.etpu_pwm_auto.h /* warning this file is automatically generated do not edit it! */ #ifndef __etpu_pwm_auto_h #define __etpu_pwm_auto_h /* function configuration information */ #define etpu_pwm_function_number 5 #define etpu_pwm_table_select 0 #define etpu_pwm_num_parms 0x0010 #define etpu_pwm_int_enable 0 #define etpu_pwm_dma_enable 0 #define etpu_pwm_out_dis 0 #define etpu_pwm_func_mode 0 /* host service request definitions */ #define etpu_pwm_init 1 #define etpu_pwm_update 3 /* parameter definitions */ #define etpu_pwm_period_offset (( 0x0001 - 1)/4) #define etpu_pwm_duty_offset ( 0x0005 - 1)/4 /* global variables image for etpuc_pwm.c*/ #endif /*__etpu_pwm_auto_h */
code example 6.utility.c AN2618 18/23 appendix f code example 6.utility.c /******************************************************************************** * function: mc_etpu_init * * purpose: this function initialize the etpu module including * * 1. initialize global registers * * 2. load etpu code into memory * * 3. copy initial values of global variables to data ram * ********************************************************************************/ uint32_t mc_etpu_init( struct etpu_config_t p_etpu_config, uint32_t *code, uint8_t codesize, uint32_t *globals) { uint32_t *code_end; uint32_t unused_code_ram; unused_code_ram = (((etpu.mcr.b.scmsize - 1 ) * 1024) - (uint32_t)codesize*1024); if ( unused_code_ram < 0 ) return((uint32_t)etpu_error_codesize); /* 1. initialize global registers */ etpu.misccmpr.r = p_etpu_config.misc; //write misc value before it is enable in mcr etpu.mcr.r = p_etpu_config.mcr; /* configure engine 1 */ etpu.tbcr_1.r = p_etpu_config.tbcr_1; etpu.stacr_1.r = p_etpu_config.stacr_1; etpu.ecr_1.r = p_etpu_config.ecr_1; /* configure engine 2 */ etpu.tbcr_2.r = p_etpu_config.tbcr_2; etpu.stacr_2.r = p_etpu_config.stacr_2; etpu.ecr_2.r = p_etpu_config.ecr_2; /* load microcode */ /* in order to write the etpu code ram, both etpu engine has to be stopped. */ /* stopping etpu engine can be achieved by set low power stop bit. */ etpu.ecr_1.b.mdis = 1; etpu.ecr_2.b.mdis = 1; /* enable writing to scm */ etpu.mcr.b.vis = 1; /* 2. copy microcode */ mc_memcpy32( &code_ram, code, (uint32_t)codesize*1024); /* disable writing to scm */ etpu.mcr.b.vis = 0; /* 3. copy initial global values to parameter ram. */ mc_memcpy32 ( &data_ram, globals, etpu_global_mem_size); /* after writing the etpu code ram, both etpu engine has to be re-started. */ /* restart etpu engine can be achieved by clear low power stop bit. */ etpu.ecr_1.b.mdis = 0; etpu.ecr_2.b.mdis = 0; return((uint32_t) 0); }
AN2618 code example 6.utility.c 19/23 /******************************************************************************** * function: mc_etpu_chan_init * * purpose: this function initialize the etpu channel including * * 1. assign the etpu function to channel * * 2. configure the channel * * 3. calculate and auto assign function frame * ********************************************************************************/ uint16_t mc_etpu_chan_init( uint8_t channel, uint8_t function, uint8_t mode, \ uint8_t num_param, uint32_t config, uint16_t func_frame) { if (func_frame == 0) { func_frame = mc_etpu_malloc(num_param); if (func_frame == 0) return((uint16_t)etpu_error_malloc); } etpu.chan[channel].cr.r = config + (function<<16) + (func_frame>>3); etpu.chan[channel].scr.r = mode; return(func_frame); } /******************************************************************************** * function: mc_etpu_malloc * * purpose: this function calculates the memory space for a etpu function based * * the number and size of the parameter as well as the static local * * variable for a etpu function. the function returns the address at * * which the next function frame can be assigned. * ********************************************************************************/ uint16_t mc_etpu_malloc( uint16_t num_params) { static uint16_t etpu_pram_used = etpu_pram_start_addr; uint16_t next_function_frame = etpu_pram_used; //each parameter takes 4 bytes, check if there is enough space available if ((etpu_pram_used + num_params<<2) > etpu_pram_size) return(0); else etpu_pram_used += (num_params<<2); //scale the pointer for the function frame return (next_function_frame); }
code example 7.etpu_pwm.c AN2618 20/23 appendix g code example 7.etpu_pwm.c #include "etpu_constants.h" #include "etpu_pwm_auto.h" #define etpu_pse_ram_offset 0x1000 /******************************************************************************** * function: etpu_pwm_init * * purpose: this function executes on the host cpu. * * the function checks validity for parameters then pass them to * * the etpu functions. the function issue the host service request to * * etpu pwm function to initiate the execution. * ********************************************************************************/ int etpu_pwm_init(unsigned char channel, unsigned long period, unsigned long duty) { int errorcode = 0; unsigned long functframe = etpu.chan[channel].cr.b.cpba; unsigned long *pba_32 = &data_ram + (functframe << 1) + etpu_pse_ram_offset; // function parameter validity check if (period > 0xffffff) { errorcode = param_out_range; period = 0xffffff; } if (duty > 0xffffff) { errorcode = param_out_range; duty = 0xffffff; } // passing function parameter to etpu function frame *(pba_32 + etpu_pwm_period_offset) = period; *(pba_32 + etpu_pwm_duty_offset) = duty; //write hsr etpu.chan[channel].hsrr.r = etpu_pwm_init; return (errorcode); } /******************************************************************************** * function: etpu_pwm_update * * purpose: this function executes on the host cpu. * * this function checks validity for parameters then pass them to * * the etpu functions. the function issue the host service request to * * etpu pwm function to update the function parameters. * ********************************************************************************/ int etpu_pwm_update(unsigned char channel, unsigned long period, unsigned long duty) { int errorcode = 0; unsigned long functframe = etpu.chan[channel].cr.b.cpba; unsigned long *pba_32 = &data_ram + (functframe << 1) + etpu_pse_ram_offset; // function parameter validity check if (period > 0xffffff) { errorcode = param_out_range; period = 0xffffff;
AN2618 code example 7.etpu_pwm.c 21/23 } if (duty > 0xffffff) { errorcode = param_out_range; duty = 0xffffff; } // passing function parameter to etpu function frame *(pba_32 + etpu_pwm_period_offset) = period; *(pba_32 + etpu_pwm_duty_offset) = duty; //write hsr etpu.chan[channel].hsrr.r = etpu_pwm_update; return (errorcode); } /******************************************************************************** * function : etpu_pwm_getpulsetime * * purpose: this function executes on the host cpu. * * this function is an application api to read the time stamp of the * * begining of the last peroid of the pwm output on the eptu channel. * ********************************************************************************/ int16_t etpu_pwm_getpulsetime(uint8_t channel, uint32_t * starttime) { int16_t errorcode = 0; uint32_t functframe = etpu.chan[channel].cr.b.cpba; uint32_t *pba_32 = &data_ram + (functframe << 1) + etpu_pse_ram_offset; // passing function parameter to etpu function frame *starttime = *(pba_32 + etpu_pwm_pulse_time_offset); return (errorcode); }
revision history AN2618 22/23 6 revision history table 1. document revision history date revision changes 11-sep-2007 1 initial release. 17-sep-2013 2 updated disclaimer
AN2618 23/23 please read carefully: information in this document is provided solely in connection with st products. stmicroelectronics nv and its subsidiaries (?st ?) reserve the right to make changes, corrections, modifications or improvements, to this document, and the products and services described he rein at any time, without notice. all st products are sold pursuant to st?s terms and conditions of sale. purchasers are solely responsible for the choice, selection and use of the st products and services described herein, and st as sumes no liability whatsoever relating to the choice, selection or use of the st products and services described herein. no license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. i f any part of this document refers to any third party products or services it shall not be deemed a license grant by st for the use of such third party products or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoev er of such third party products or services or any intellectual property contained therein. unless otherwise set forth in st?s terms and conditions of sale st disclaims any express or implied warranty with respect to the use and/or sale of st products including without limitation implied warranties of merchantability, fitness for a particul ar purpose (and their equivalents under the laws of any jurisdiction), or infringement of any patent, copyright or other intellectual property right. st products are not designed or authorized for use in: (a) safety critical applications such as life supporting, active implanted devices or systems with product functional safety requirements; (b) aeronautic applications; (c) automotive applications or environments, and/or (d) aerospace applications or environments. where st products are not designed for such use, the purchaser shall use products at purchaser?s sole risk, even if st has been informed in writing of such usage, unless a product is expressly designated by st as being intended for ? automotive, automotive safe ty or medical? industry domains according to st product design specifications. products formally escc, qml or jan qualified are deemed suitable for use in aerospace by the corresponding governmental agency. resale of st products with provisions different from the statements and/or technical features set forth in this document shall immediately void any warranty granted by st for the st product or service described herein and shall not create or extend in any manner whatsoev er, any liability of st. st and the st logo are trademarks or registered trademarks of st in various countries. information in this document supersedes and replaces all information previously supplied. the st logo is a registered trademark of stmicroelectronics. all other names are the property of their respective owners. ? 2013 stmicroelectronics - all rights reserved stmicroelectronics group of companies australia - belgium - brazil - canada - china - czech republic - finland - france - germany - hong kong - india - israel - ital y - japan - malaysia - malta - morocco - philippines - singapore - spain - sweden - switzerland - united kingdom - united states of america www.st.com


▲Up To Search▲   

 
Price & Availability of AN2618

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X